package net.lgy.apitest.config;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;


import net.lgy.apitest.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                //添加拦截的路径 - 拦截所有请求
                .addPathPatterns("/**")

                //排除不拦截的路径
                .excludePathPatterns(
                        // 静态资源
                        "/css/**", "/js/**", "/images/**", "/fonts/**", "/static/**",
                        // 健康检查
                        "/health/**", "/actuator/**",
                        // 文档相关
                        "/swagger-ui/**", "/v3/api-docs/**", "/doc.html", "/webjars/**",
                        // 登录注册相关
                        "/api/account/*/register", "/api/account/*/login", "/api/account/*/upload_avatar",
                        // 分享相关公开接口
                        "/api/share/*/check_share_code", "/api/share/*/visit", "/api/share/*/detail_no_code", "/api/share/*/detail_with_code",
                        // 其他公开接口
                        "/api/public/**", "/api/test/**"
                );
    }

}